package org.com.blbl.LikesRank;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class LikeRankMapper extends Mapper<LongWritable, Text, LongWritable, Text> {

    LongWritable outKey = new LongWritable();
    Text outValue = new Text();

    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, LongWritable, Text>.Context context) throws IOException, InterruptedException {
        String[] fields = value.toString().split(",");

        Long likes = Long.parseLong(fields[fields.length - 4]);
        outKey.set(likes);

        String upz = fields[1];
        outValue.set(upz);

        context.write(outKey, outValue);
    }
}
